#include "MatrixCamera.h"

MatrixCamera::MatrixCamera(const Eigen::Vector3f& position,
						   const Eigen::Vector3f& view, const Eigen::Vector3f& up,
						   const Eigen::Vector3f& right)
{
	_position = position;
	mView = view;
	mView = Eigen::Vector3f::UnitZ();
	mUp = up;
	mRight = right;
}

MatrixCamera::~MatrixCamera(void)
{
}

Eigen::Vector3f MatrixCamera::view() const
{
	return mView;
}

Eigen::Vector3f MatrixCamera::up() const
{
	return mUp;
}

Eigen::Vector3f MatrixCamera::right() const
{
	return mRight;
}

void MatrixCamera::setView(Eigen::Vector3f view)
{
	mView = view;
}
void MatrixCamera::setUp(Eigen::Vector3f up)
{
	mUp = up;
}
void MatrixCamera::setRight(Eigen::Vector3f right)
{
	mRight = right;
}


Eigen::Transform3f MatrixCamera::transform() const
{
	Transform3f transform( VectorUtils::IdentityTransform );
	return transform;
}

void MatrixCamera::setTransform( const Eigen::Transform3f &transform )
{
	// extract translation part -- position
	// transform.translation();

	Matrix3f matrix = transform.linear();
	mView = matrix * mView;
	mUp = matrix * mUp;
	mRight = matrix * mRight;
	mView.normalize();
	mUp.normalize();
	mRight.normalize();
}

void MatrixCamera::setRotation( const Vector3f& rotation )
{

	Matrix3f matrix = Matrix3f( AngleAxisf( rotation.y(), Vector3f::UnitY() ) *
		AngleAxisf( rotation.x(), Vector3f::UnitX() ) );
	mView = matrix * mView;
	mUp = matrix * mUp;
	mRight = matrix * mRight;
	mView.normalize();
	mUp.normalize();
	mRight.normalize();
}

void MatrixCamera::rotate( const Eigen::Vector3f &delta )
{
	//setRotation( _rotation + delta );
}
/*! Translates the camera in world space. */
void MatrixCamera::translate( const Eigen::Vector3f &delta )
{
	_position[0]+=mView[0]*delta[0];
	_position[1]+=mView[1]*delta[1];
	_position[2]+=mView[2]*delta[2];
}
